Skip to main content

All Questions

0votes
1answer
1kviews

Mock a bean with 10 methods when I only use one?

I face some situations similar to the following simplified one: @Component class ServiceOne { @Autowired ServiceTwo two; void act() { ... two.a(); ... } } @...
ch271828n's user avatar
0votes
2answers
238views

Is there any benefit testing only with mocks/fakes/doubles?

Say I want to test the behavior of the GUI while I follow a PassiveView approach. I also use the command pattern to handle the actions of the user. So given a PersonView and a PersonService with a ...
George Z.'s user avatar
6votes
1answer
16kviews

Should I mock ObjectMapper in my unit tests?

I have different services in a spring application that have a dependency on Jackson ObjectMapper, the unit tests rely on @InjectMocks to inject all the various dependencies to the class that is under ...
Pampa Nello's user avatar
0votes
1answer
85views

Should all third party methods that access outside resources (like other databases) be wrapped up?

From the perspective of unit testing, the code under test should obviously not be accessing outside resources so the third party methods need to be mocked. However, it seems like this is poor practice ...
JobHunter69's user avatar
3votes
4answers
1kviews

How do I deal with the fact that I am forced to make helper functions public for testing purposes?

I've encountered several scenarios that require me to mock certain helper methods because they call outside resources. As a result, I'm forced to convert all my helper methods from private into public....
JobHunter69's user avatar
6votes
3answers
7kviews

What is recommended way to create test data for unit test cases?

I am new to TDD/unit testing. I am going to write a complex scheduling algorithm in Java. As this module is a core part of our application and there are number of scenarios in it, I want to write ...
Bhushan's user avatar
1vote
1answer
130views

Mocked dependencies verification - Best practices

I have a simple question about best practices in unit test verifications. Given this example: @Test public void methodUnderTest() { when(mockedDependency.someMethod()).thenReturn(someValue); ...
Bronx's user avatar
2votes
2answers
4kviews

Testing using mocking, must I mock all dependencies too?

I have the following method to test: public List<MarkId> getMarkIdList(ICar carDoc) { ICourseCar courseCarDoc = courseCarRep.get(carDoc); List<MarkWag> markWagList = ...
user1883212's user avatar
3votes
1answer
12kviews

Should I use a mock or create a new instance of an object in unit tests? [closed]

I have to write a unit test for a method like: void doSomethingWith(Country country) {...} There are the following classes: Interface: public interface Country { String getName(); ... // and a ...
Ales's user avatar
3votes
2answers
5kviews

Converting static utility class into singleton

In company where I work we have lots of "utility" classes, each has lots of code inside (thousands of lines), and they are all static. And one static methods call anothers. The problem here is that ...
maxpovver's user avatar
4votes
2answers
886views

Domain object model: query by id vs object

Let assume I have two simple model classes: Product and Brand It is obvious I have a query method in Product class like this Product product = Product.findById(123); What if, I want to query ...
Yoga's user avatar
  • 325
5votes
3answers
2kviews

how and should I 'unit test' an entire package?

I'm still learning to be good about doing unit level testing, as I've always been a little sloppy about only doing functional testing in the past, so I want to double check I'm doing this 'right'. I ...
dsollen's user avatar
  • 1,153
0votes
1answer
1kviews

Method visibility for testing partial mocks

I'm currently writing unit tests to test behavior of a method and would like to partially mock the methods calling injected properties. For example: public void doSomething() { int complicatedInt =...
dardo's user avatar
11votes
3answers
8kviews

Mocking concrete class - Not recommended

I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended. Here some sample code of a unit-test for the ...
Mik378's user avatar
  • 3,916
7votes
7answers
3kviews

Is mocking for unit testing appropriate in this scenario?

I have written around 20 methods in Java and all of them call some web services. None of these web services are available yet. To carry on with the server side coding, I hard-coded the results that ...
Vinoth Kumar C M's user avatar

153050per page
close